package com.mlethe.android.demo.recyclerview.adapter;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;

import com.mlethe.android.demo.recyclerview.adapter.adapter.FieldGuildGridAdapter;
import com.mlethe.android.demo.recyclerview.adapter.entity.CatDaoEntity;
import com.mlethe.android.demo.recyclerview.adapter.util.DisplayHelper;
import com.mlethe.demo.recyclerview.adapter.R;
import com.mlethe.library.recyclerview.decoration.PagerGridItemDecoration;
import com.mlethe.library.recyclerview.pagergrid.PagerGridLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class NewViewPagerActivity extends AppCompatActivity {

    private RecyclerView recyclerView;

    private FieldGuildGridAdapter mAdapter = new FieldGuildGridAdapter();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_view_pager);
        recyclerView = findViewById(R.id.recyclerView);
        int width = (DisplayHelper.getScreenWidth(this) - DisplayHelper.dp2px(this, 23) * 2 - DisplayHelper.dp2px(this, 4) * 2);
        int row = 4;
        int column = 4;
        List<CatDaoEntity> list = new ArrayList<>();
        for (int i = 0; i < 41; i++) {
            list.add(new CatDaoEntity());
        }
//        mAdapter.setData(list);
        ((DefaultItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
        PagerGridLayoutManager layoutManager = new PagerGridLayoutManager(row, column, PagerGridLayoutManager.HORIZONTAL);
//        layoutManager.setVerticalMarginSize(this, 14f, 10f, 15f)
//                .setHorizontalMarginSize(this, 10f, 10f, 15f);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        recyclerView.setAdapter(mAdapter);
        recyclerView.addItemDecoration(new PagerGridItemDecoration(this)
                .setHorizontalSize(10f)
                .setVerticalSize(14f)
                .setHorizontalMarginSize(18f)
                .setVerticalMarginSize(10f, 15f)
                .setMarginDrawable(R.mipmap.ic_stcs_btm_line)
                .setDrawable(R.mipmap.ic_stcs_btm_line));
        mAdapter.setData(list);
//            mAdapter.setNewData(list);
            /*recyclerView.post(() -> {
                recyclerView.scrollToPosition(mAdapter.index / 3 * 3);
            });*/
    }

}